﻿using B.S.Data.MES.API.Applications.BaseData.Command.BOMCommand;
using B.S.Domain.BasicData.MaterialManagement.BOM;
using B.S.Infratrctrue;
using B.S.Requst;
using MediatR;

namespace B.S.Data.MES.API.Applications.BaseData.CommandHandlers.BOMCommandHandlers
{
    public class GetBomCommandHandler : IRequestHandler<GetBomCommand, APIRequst<List<BOM>>>
    {
        private readonly IBaseRepository<BOM> _bomRepository;
        public GetBomCommandHandler(IBaseRepository<BOM> bomRepository)
        {
            _bomRepository = bomRepository;
        }
        public Task<APIRequst<List<BOM>>> Handle(GetBomCommand request, CancellationToken cancellationToken)
        {
            var show = _bomRepository.GetAll().Where(x=>!x.isDel);
            if(!string.IsNullOrEmpty(request.Materialcode))
            {
                show=show.Where(x=>x.Materialcode.Contains(request.Materialcode));
            }
            return Task.FromResult(new APIRequst<List<BOM>>
            {
                Data=show.ToList(),
                Code=RequstCode.成功,
                Msg=RequstCode.成功.ToString()
            });
        }
    }
}

